export default {
    //毫秒转字符串
    date(val){
        if(!val) return;

        let newDate = new Date(val),
            dateYear = newDate.getFullYear(),
            dateMonth = newDate.getMonth() + 1,
            dateDay = newDate.getDate(),
            dateArray = [dateYear,dateMonth,dateDay];
            dateArray = dateArray.map(val => {
                return val > 9 ? val : `0${val}`;
            });
        return dateArray.join('-');
    },

    dateTime(val){
        if(!val) return;

        let newDate = new Date(val),
            dateYear = newDate.getFullYear(),
            dateMonth = newDate.getMonth() + 1,
            dateDay = newDate.getDate(),
            dateHour = newDate.getHours(),
            dateMinute = newDate.getMinutes(),
            dateSecond = newDate.getSeconds(),
            dateTimeArray = [dateHour,dateMinute,dateSecond],
            dateArray = [dateYear,dateMonth,dateDay];

        dateArray = dateArray.map(val => {
            return val > 9 ? val : `0${val}`;
        });
        dateTimeArray = dateTimeArray.map(val => {
            return val > 9 ? val : `0${val}`;
        });
        return `${dateArray.join('-')} ${dateTimeArray.join(':')}`;
    },


    //姓名加密
    formatCustName(custName) {
        var val = '';
        if (custName) {
            val = custName.substring(0, 1) + '**';
        }
        return val;
    },

    //身份证号码加密
    formatIdCard(idCard) {
        var val = '';
        if (idCard) {
            val = idCard.substring(0, 4) + '******' + idCard.substring(idCard.length - 4);
        }
        return val;
    },

}
